﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EIA.PM.DAL;
using EIA.PM.Model;
using System.Collections;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.Data;
using System.Collections.ObjectModel;

namespace EIA.PM.BLL
{
    public class XProjectInfoBlp : IXProjectInfoBlp
    {
        private string contract_amount_1 ;//院
        private string contract_amount_2 ;//公司
        private string contract_amount ;
        private string invoice_amount_1;
        private string invoice_amount_2 ;
        private string invoice_amount ;
        private string ContractAndInvoiceAmount;
        public XProjectInfoBlp()
        {
        }

        public IList<XProjectInfo> Query(string sSQL)
        {
            List<XProjectInfo> lst = new List<XProjectInfo>();
            MySqlConnection conn = getMysqlConn();
            try
            {
                
                //MySqlCommand mySqlCommand = getSqlCommand(sSQL, mysql);
                conn.Open();
                MySqlDataAdapter mda = new MySqlDataAdapter(sSQL, conn);
                DataSet ds = new DataSet();
                mda.Fill(ds, "table1");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string stfName = string.Empty;
                    string workRate = string.Empty;
                    //double invoice_amount = 0;
                    //double receipt_amount = 0;
                    getPrjMember(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out stfName, out workRate);
                    //getPrjInvoiceAmount(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out invoice_amount);
                    //getPrjReceiptAmount(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out receipt_amount);
                    lst.Add(new XProjectInfo()
                    {
                        PrjId = ds.Tables[0].Rows[i]["prj_id"].ToString(),
                        PrjName = ds.Tables[0].Rows[i]["prj_name"].ToString(),
                        PrjConsOrg = ds.Tables[0].Rows[i]["prj_cons_org"].ToString(),
                        PrjType = int.Parse(ds.Tables[0].Rows[i]["prj_type"].ToString()),
                        PrjSource = int.Parse(ds.Tables[0].Rows[i]["prj_source"].ToString()),
                        PrjLeader = ds.Tables[0].Rows[i]["prj_leader_name"].ToString(),
                        PrjEngineer = ds.Tables[0].Rows[i]["prj_engineer_name"].ToString(),
                        PrjMember = stfName==string.Empty?"":stfName.Substring(0, stfName.Length - 1),
                        PrjWorkRate = workRate==string.Empty?"":workRate.Substring(0, workRate.Length - 1),
                        PrjBegindate = DateTime.Parse(ds.Tables[0].Rows[i]["prj_begin_date"].ToString()).ToString("yyyy-MM-dd"),
                        PrjScheduledDate = DateTime.Parse(ds.Tables[0].Rows[i]["prj_scheduled"].ToString()).ToString("yyyy-MM-dd"),
                        PrjProgress = ds.Tables[0].Rows[i]["_progress"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[i]["_progress"].ToString()),
                        PrjDepId = int.Parse(ds.Tables[0].Rows[i]["dep_id"].ToString()),
                        PrjDepName = ds.Tables[0].Rows[i]["dep_name"].ToString(),
                        PrjContractAmount = ds.Tables[0].Rows[i]["contract_amount"].ToString()==""?0:double.Parse(ds.Tables[0].Rows[i]["contract_amount"].ToString()),
                        PrjSignedAs = ds.Tables[0].Rows[i]["prj_contract_signed_as"].ToString()==""?9:int.Parse(ds.Tables[0].Rows[i]["prj_contract_signed_as"].ToString()),
                        PrjIsSigned = ds.Tables[0].Rows[i]["_contract"].ToString()==""?0:int.Parse(ds.Tables[0].Rows[i]["_contract"].ToString()),
                        PrjReceiptAmount = ds.Tables[0].Rows[i]["receipt_amount"].ToString()==""?0:double.Parse(ds.Tables[0].Rows[i]["receipt_amount"].ToString()),
                        PrjReceiptWay = ds.Tables[0].Rows[i]["receipt_way"].ToString()==""?9:int.Parse(ds.Tables[0].Rows[i]["receipt_way"].ToString()),
                        PrjReceiptdate = ds.Tables[0].Rows[i]["receipt_date"].ToString()==""?"":DateTime.Parse(ds.Tables[0].Rows[i]["receipt_date"].ToString()).ToString("yyyy-MM-dd"),
                        PrjInvoiceState = ds.Tables[0].Rows[i]["_invoice"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[i]["_invoice"].ToString()),
                        PrjBonusState = ds.Tables[0].Rows[i]["_bonus_apply"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[i]["_bonus_apply"].ToString()),
                        PrjFieldState = ds.Tables[0].Rows[i]["_filed"].ToString()==""?0:int.Parse(ds.Tables[0].Rows[i]["_filed"].ToString()),
                    });
                }
                return lst;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
            }
            
        }

        public IList<XProjectInfo> QueryContract(string sSQL)
        {
            List<XProjectInfo> lst = new List<XProjectInfo>();
            MySqlConnection conn = getMysqlConn();
            try
            {
                //MySqlCommand mySqlCommand = getSqlCommand(sSQL, mysql);
                conn.Open();
                MySqlDataAdapter mda = new MySqlDataAdapter(sSQL, conn);
                DataSet ds = new DataSet();
                mda.Fill(ds, "table1");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    double invoice_amount = 0;
                    double receipt_amount = 0;
                    getPrjInvoiceAmount(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out invoice_amount);
                    getPrjReceiptAmount(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out receipt_amount);
                    lst.Add(new XProjectInfo()
                    {
                        PrjId = ds.Tables[0].Rows[i]["prj_id"].ToString(),
                        PrjName = ds.Tables[0].Rows[i]["prj_name"].ToString(),
                        PrjContractNo = ds.Tables[0].Rows[i]["contract_no"].ToString() == "" ? "-" : ds.Tables[0].Rows[i]["contract_no"].ToString(),
                        PrjConsOrg = ds.Tables[0].Rows[i]["prj_cons_org"].ToString() == "" ? "-" : ds.Tables[0].Rows[i]["prj_cons_org"].ToString(),
                        PrjType = int.Parse(ds.Tables[0].Rows[i]["prj_type"].ToString()),
                        PrjSource = int.Parse(ds.Tables[0].Rows[i]["prj_source"].ToString()),
                        PrjLeader = ds.Tables[0].Rows[i]["prj_leader_name"].ToString(),
                        PrjDepName = ds.Tables[0].Rows[i]["dep_name"].ToString(),
                        PrjContractAmount = ds.Tables[0].Rows[i]["contract_amount"].ToString() == "" ? 0 : double.Parse(ds.Tables[0].Rows[i]["contract_amount"].ToString()),
                        PrjSignedAs = ds.Tables[0].Rows[i]["prj_contract_signed_as"].ToString() == "" ? 9 : int.Parse(ds.Tables[0].Rows[i]["prj_contract_signed_as"].ToString()),
                        PrjIsSigned = ds.Tables[0].Rows[i]["_contract"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[i]["_contract"].ToString()),
                        PrjSignedDate = ds.Tables[0].Rows[i]["signed_date"].ToString() == "" ? "" : DateTime.Parse(ds.Tables[0].Rows[i]["signed_date"].ToString()).ToString("yyyy-MM-dd"),
                        PrjReceiptAmount = receipt_amount,
                        PrjRegion = ds.Tables[0].Rows[i]["prj_region"].ToString() == "" ? 11 : int.Parse(ds.Tables[0].Rows[i]["prj_region"].ToString()),
                        PrjApproveGov = ds.Tables[0].Rows[i]["prj_approve_gov"].ToString() == "" ? 11 : int.Parse(ds.Tables[0].Rows[i]["prj_approve_gov"].ToString()),
                        PrjInvoiceState = ds.Tables[0].Rows[i]["_invoice"].ToString() == "" ? 0 : int.Parse(ds.Tables[0].Rows[i]["_invoice"].ToString()),
                        PrjInvoiceAmount = invoice_amount,
                    });
                }
                return lst;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
            }

        }

        public string QueryContractAndInvoiceAmount(string beginData,string endData)
        {
            MySqlConnection conn = getMysqlConn();
            contract_amount_1 = "";
            contract_amount_2="";
            contract_amount="";
            invoice_amount_1="";
            invoice_amount_2="";
            invoice_amount="";
            ContractAndInvoiceAmount = "";
            try
            {
                conn.Open();
                string contract_amount_1_sql =@"select sum(t1.contract_amount) as '合同额',t3.dep_name as '业务部门' from t_project_contract t1,t_project_basic t2,t_staff t3
where t1.prj_contract_signed_as = '1' and t1.prj_id = t2.prj_id and t2.prj_leader = t3.stf_id and t1.signed_date >='{0}' and t1.signed_date <='{1}' group by t3.dep_name;";
                string contract_amount_2_sql = @"select sum(t1.contract_amount) as '合同额',t3.dep_name as '业务部门' from t_project_contract t1,t_project_basic t2,t_staff t3
where t1.prj_contract_signed_as = '2' and t1.prj_id = t2.prj_id and t2.prj_leader = t3.stf_id and t1.signed_date >='{0}' and t1.signed_date <='{1}' group by t3.dep_name;"; ;
                string contract_amount_sql = @"select sum(t1.contract_amount) as '合同额',t3.dep_name as '业务部门' from t_project_contract t1,t_project_basic t2,t_staff t3
where  t1.prj_id = t2.prj_id and t2.prj_leader = t3.stf_id and t1.signed_date >='{0}' and t1.signed_date <='{1}' group by t3.dep_name;"; ;
                string invoice_amount_1_sql = @"select sum(t4.invoice_amount) as '开票额', t3.dep_name as '业务部门' 
from t_project_contract t1,t_project_basic t2,t_staff t3,f_invoice t4 where t1.prj_id = t2.prj_id and t2.prj_leader = t3.stf_id 
and t4.prj_id = t1.prj_id and t1.prj_contract_signed_as = '1' group by t3.dep_name;";
                string invoice_amount_2_sql = @"select sum(t4.invoice_amount) as '开票额', t3.dep_name as '业务部门' 
from t_project_contract t1,t_project_basic t2,t_staff t3,f_invoice t4 where t1.prj_id = t2.prj_id and t2.prj_leader = t3.stf_id 
and t4.prj_id = t1.prj_id and t1.prj_contract_signed_as = '2' group by t3.dep_name;";
                string invoice_amount_sql = @"select sum(t4.invoice_amount) as '开票额', t3.dep_name as '业务部门' 
from t_project_contract t1,t_project_basic t2,t_staff t3,f_invoice t4 where t1.prj_id = t2.prj_id and t2.prj_leader = t3.stf_id 
and t4.prj_id = t1.prj_id group by t3.dep_name;";
                contract_amount_1_sql = string.Format(contract_amount_1_sql, beginData, endData);
                contract_amount_2_sql = string.Format(contract_amount_2_sql, beginData, endData);
                contract_amount_sql = string.Format(contract_amount_sql, beginData, endData);
                invoice_amount_1_sql = string.Format(invoice_amount_1_sql, beginData, endData);
                invoice_amount_2_sql = string.Format(invoice_amount_2_sql, beginData, endData);
                invoice_amount_sql = string.Format(invoice_amount_sql, beginData, endData);
                MySqlDataAdapter mda = new MySqlDataAdapter(contract_amount_1_sql, conn);
                DataSet ds_contract_1 = new DataSet();
                DataSet ds_contract_2 = new DataSet();
                DataSet ds_contract = new DataSet();
                DataSet ds_invoice_1 = new DataSet();
                DataSet ds_invoice_2 = new DataSet();
                DataSet ds_invoice = new DataSet();
                mda.Fill(ds_contract_1, "table1");
                mda = new MySqlDataAdapter(contract_amount_2_sql, conn);
                mda.Fill(ds_contract_2, "table1");
                mda = new MySqlDataAdapter(contract_amount_sql, conn);
                mda.Fill(ds_contract, "table1");
                mda = new MySqlDataAdapter(invoice_amount_1_sql, conn);
                mda.Fill(ds_invoice_1, "table1");
                mda = new MySqlDataAdapter(invoice_amount_2_sql, conn);
                mda.Fill(ds_invoice_2, "table1");
                mda = new MySqlDataAdapter(invoice_amount_sql, conn);
                mda.Fill(ds_invoice, "table1");
                for (int i1 = 0; i1 < ds_contract_1.Tables[0].Rows.Count; i1++)
                {
                    if (string.IsNullOrEmpty(ds_contract_1.Tables[0].Rows[i1]["合同额"].ToString()))
                    {
                        contract_amount_1 = contract_amount_1 + "0" + ",";
                    }
                    else
                    {
                        contract_amount_1 = contract_amount_1 + ds_contract_1.Tables[0].Rows[i1]["合同额"].ToString().Trim()+",";
                    }
                }
                for (int i2 = 0; i2 < ds_contract_2.Tables[0].Rows.Count; i2++)
                {
                    if (string.IsNullOrEmpty(ds_contract_2.Tables[0].Rows[i2]["合同额"].ToString()))
                    {
                        contract_amount_2 = contract_amount_2 + "0" + ",";
                    }
                    else
                    {
                        contract_amount_2 = contract_amount_2 + ds_contract_2.Tables[0].Rows[i2]["合同额"].ToString().Trim() + ",";
                    }
                }
                for (int i3 = 0; i3 < ds_contract.Tables[0].Rows.Count; i3++)
                {
                    if (string.IsNullOrEmpty(ds_contract.Tables[0].Rows[i3]["合同额"].ToString()))
                    {
                        contract_amount = contract_amount + "0" + ",";
                    }
                    else
                    {
                        contract_amount = contract_amount + ds_contract.Tables[0].Rows[i3]["合同额"].ToString().Trim() + ",";
                    }
                }
                for (int i4 = 0; i4 < ds_invoice_1.Tables[0].Rows.Count; i4++)
                {
                    if (string.IsNullOrEmpty(ds_invoice_1.Tables[0].Rows[i4]["开票额"].ToString()))
                    {
                        invoice_amount_1 = invoice_amount_1 + "0" + ",";
                    }
                    else
                    {
                        invoice_amount_1 = invoice_amount_1 + ds_invoice_1.Tables[0].Rows[i4]["开票额"].ToString() + ",";
                    }
                }
                for (int i5 = 0; i5 < ds_invoice_2.Tables[0].Rows.Count; i5++)
                {
                    if (string.IsNullOrEmpty(ds_invoice_2.Tables[0].Rows[i5]["开票额"].ToString()))
                    {
                        invoice_amount_2 = invoice_amount_2 + "0" + ",";
                    }
                    else
                    {
                        invoice_amount_2 = invoice_amount_2 + ds_invoice_2.Tables[0].Rows[i5]["开票额"].ToString() + ",";
                    }
                }
                for (int i6 = 0; i6 < ds_invoice.Tables[0].Rows.Count; i6++)
                {
                    if (string.IsNullOrEmpty(ds_invoice.Tables[0].Rows[i6]["开票额"].ToString()))
                    {
                        invoice_amount = invoice_amount + "0" + ",";
                    }
                    else
                    {
                        invoice_amount = invoice_amount + ds_invoice.Tables[0].Rows[i6]["开票额"].ToString() + ",";
                    }
                }
                ContractAndInvoiceAmount = contract_amount_1 + ";" + invoice_amount_1 + ";" + contract_amount_2 + ";" + invoice_amount_2 + ";" + contract_amount + ";" + invoice_amount;
                return ContractAndInvoiceAmount;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
            }
        }

        public XProjectBonus QueryForBonus(string sSQL)
        {
            XProjectBonus projectBonus = new XProjectBonus();
            MySqlConnection conn = getMysqlConn();
            try
            {
                MySqlDataAdapter mda = new MySqlDataAdapter(sSQL, conn);
                DataSet ds = new DataSet();
                mda.Fill(ds, "table1");
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    double app_amount = 0;
                    double receipt_amount = 0;
                    string approver = string.Empty;
                    getPrjAppAmount(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out app_amount);
                    getPrjReceiptAmount(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out receipt_amount);
                    getPrjApprover(ds.Tables[0].Rows[i]["prj_id"].ToString(), conn, out approver);
                    
                    projectBonus.PrjId = ds.Tables[0].Rows[i]["prj_id"].ToString();
                    projectBonus.PrjCoopFee = ds.Tables[0].Rows[i]["prj_coop_fee"].ToString()==""?0:double.Parse(ds.Tables[0].Rows[i]["prj_coop_fee"].ToString());
                    projectBonus.PrjContractAmount = ds.Tables[0].Rows[i]["contract_amount"].ToString() == "" ? 0 : double.Parse(ds.Tables[0].Rows[i]["contract_amount"].ToString());
                    projectBonus.PrjSignedAs = ds.Tables[0].Rows[i]["prj_contract_signed_as"].ToString() == "" ? 9 : int.Parse(ds.Tables[0].Rows[i]["prj_contract_signed_as"].ToString());
                    projectBonus.WorkRate = ds.Tables[0].Rows[i]["work_rate"].ToString() == "" ? 0 : double.Parse(ds.Tables[0].Rows[i]["work_rate"].ToString());
                    projectBonus.PrjWorkAmountRate = ds.Tables[0].Rows[i]["prj_work_amount_rate"].ToString() == "" ? 0 : double.Parse(ds.Tables[0].Rows[i]["prj_work_amount_rate"].ToString());
                    projectBonus.DedAmountRemain = double.Parse(ds.Tables[0].Rows[i]["kqjs"].ToString());
                    projectBonus.DedAmount = 7 - projectBonus.DedAmountRemain;
                    projectBonus.PrjReceiptAmount = receipt_amount;
                    projectBonus.TakeAmount = app_amount;
                    projectBonus.Approver = approver;
                    if (projectBonus.PrjSignedAs == 1)
                    {
                        projectBonus.TakeAmountRemain = Math.Min((projectBonus.PrjContractAmount * projectBonus.PrjWorkAmountRate - projectBonus.PrjCoopFee), receipt_amount) - app_amount;
                    }
                    else
                    {
                        projectBonus.TakeAmountRemain = Math.Min((projectBonus.PrjContractAmount - projectBonus.PrjCoopFee), receipt_amount) - app_amount;
                    }
                    
                }
                return projectBonus;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public int UpdateKQJS(double kcjs,int stf_id)
        {
            string sql = "update t_kqjs set kqjs={0} where stf_id = {1}";
            sql = string.Format(sql, kcjs, stf_id);
            MySqlConnection conn = getMysqlConn();
            try
            {
                conn.Open();
                MySqlCommand command = new MySqlCommand(sql, conn);
                int k = command.ExecuteNonQuery();
                return k;
            }
            catch (Exception ex)
            {
                return 0;
            }
            finally
            {
                conn.Close();
            }
        }

        private void getPrjMember(string prj_id,MySqlConnection conn,out string stfName,out string workRate)
        {
            stfName = string.Empty;
            workRate = string.Empty;
            EIA.PM.Model.RProjectMember pm = new RProjectMember();
            string sql = string.Format("select * from r_project_member where prj_id ={0}",prj_id);
            MySqlDataAdapter mda = new MySqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            mda.Fill(ds, "table1");
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                stfName = stfName + ds.Tables[0].Rows[i]["stf_name"].ToString() + "/";
                workRate = workRate + ds.Tables[0].Rows[i]["work_rate"].ToString() + "/";
            }
        }

        private void getPrjInvoiceAmount(string prj_id, MySqlConnection conn, out double invoice_amount)
        {
            invoice_amount = 0;
            
            string sql = string.Format("select sum(t1.invoice_amount) from f_invoice t1 where t1.prj_id ={0} group by t1.prj_id;", prj_id);
            MySqlDataAdapter mda = new MySqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            mda.Fill(ds, "table1");
            if (ds.Tables[0].Rows.Count > 0)
            {
                try
                {
                    invoice_amount = int.Parse(ds.Tables[0].Rows[0][0].ToString());
                }
                catch (Exception ex)
                {
                    invoice_amount = 0;
                }
            }
            
        }

        private void getPrjReceiptAmount(string prj_id, MySqlConnection conn, out double receipt_amount)
        {
            receipt_amount = 0;
            string sql = string.Format("select sum(t1.receipt_amount) from f_receipt t1 where t1.prj_id ={0} group by t1.prj_id;", prj_id);
            MySqlDataAdapter mda = new MySqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            mda.Fill(ds, "table1");
            if (ds.Tables[0].Rows.Count > 0)
            {
                receipt_amount = int.Parse(ds.Tables[0].Rows[0][0].ToString());
            }
        }

        private void getPrjAppAmount(string prj_id, MySqlConnection conn, out double app_amount)
        {
            app_amount = 0;

            string sql = string.Format("select sum(app_amount) from l_bonus_apply where prj_id ={0} group by prj_id;", prj_id);
            MySqlDataAdapter mda = new MySqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            mda.Fill(ds, "table1");
            if (ds.Tables[0].Rows.Count > 0)
            {
                try
                {
                    app_amount = double.Parse(ds.Tables[0].Rows[0][0].ToString());
                }
                catch (Exception ex)
                {
                    app_amount = 0;
                }
            }
        }

        private void getPrjApprover(string prj_id, MySqlConnection conn, out string approver)
        {
            approver = string.Empty;
            string sql = string.Format(" select t2.stf_name from l_project_approve t1,t_Staff t2 where t1.progress = '6' and t1.prj_id = {0} and t1.step1_staff = t2.stf_id;", prj_id);
            MySqlDataAdapter mda = new MySqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            mda.Fill(ds, "table1");
            if (ds.Tables[0].Rows.Count > 0)
            {
                approver = ds.Tables[0].Rows[0][0].ToString();
            }
        }

        private MySqlConnection getMysqlConn()
        {
            string mysqlStr = "Database=eiampdb;Data Source=127.0.0.1;User Id=root;Password=root";
            MySqlConnection mysql = new MySqlConnection(mysqlStr);
            return mysql;
        }

        private MySqlCommand getSqlCommand(String sql, MySqlConnection mysql)
        {
            MySqlCommand mySqlCommand = new MySqlCommand(sql, mysql);
            return mySqlCommand;
        }

        public void LoadDicTypeCollection()
        {
            EIA.Basic.BLL.DicItemBlp diBlp = new Basic.BLL.DicItemBlp();
            List<EIA.Basic.Model.DicItem> lst = diBlp.ListAll().ToList<EIA.Basic.Model.DicItem>();
            
                AllDicItemCollection = new ObservableCollection<Basic.Model.DicItem>(lst);

                var l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.HYLX select di;
                if (l != null) HYLXCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMLX select di;
                if (l != null) XMLXCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMSZD select di;
                if (l != null) XMSZDCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMSPBM select di;
                if (l != null) XMSPBMCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMLY select di;
                if (l != null) XMLYCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMJD select di;
                if (l != null) XMJDCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.DKFS select di;
                if (l != null) DKFSCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.HTQDZT select di;
                if (l != null) HTQDZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.HTZT select di;
                if (l != null) HTZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.KPZT select di;
                if (l != null) KPZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.DKZT select di;
                if (l != null) DKZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.GDZT select di;
                if (l != null) GDZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.BGYP select di;
                if (l != null) BGYPCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.XMYQSPZT select di;
                if (l != null) XMYQSPZTCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

                l = from EIA.Basic.Model.DicItem di in lst where di.DicTid == DicTypes.TJXS select di;
                if (l != null) TJXSCollection = new ObservableCollection<EIA.Basic.Model.DicItem>(l);

        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _AllDicItemCollection;
        /// <summary>
        /// 所有字典项
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> AllDicItemCollection
        {
            get { return _AllDicItemCollection; }
            set
            {
                _AllDicItemCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _HYLXCollection;
        /// <summary>
        /// 行业类型
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> HYLXCollection
        {
            get { return _HYLXCollection; }
            set
            {
                _HYLXCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMLXCollection;
        /// <summary>
        /// 项目类型
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMLXCollection
        {
            get { return _XMLXCollection; }
            set
            {
                _XMLXCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMSZDCollection;
        /// <summary>
        /// 项目所在地
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMSZDCollection
        {
            get { return _XMSZDCollection; }
            set
            {
                _XMSZDCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMSPBMCollection;
        /// <summary>
        /// 项目审批部门
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMSPBMCollection
        {
            get { return _XMSPBMCollection; }
            set
            {
                _XMSPBMCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMLYCollection;
        /// <summary>
        /// 项目来源
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMLYCollection
        {
            get { return _XMLYCollection; }
            set
            {
                _XMLYCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMJDCollection;
        /// <summary>
        /// 项目进度
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMJDCollection
        {
            get { return _XMJDCollection; }
            set
            {
                _XMJDCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _DKFSCollection;
        /// <summary>
        /// 到款方式
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> DKFSCollection
        {
            get { return _DKFSCollection; }
            set
            {
                _DKFSCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _HTQDZTCollection;
        /// <summary>
        /// 合同签订主体
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> HTQDZTCollection
        {
            get { return _HTQDZTCollection; }
            set
            {
                _HTQDZTCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _HTZTCollection;
        /// <summary>
        /// 合同状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> HTZTCollection
        {
            get { return _HTZTCollection; }
            set
            {
                _HTZTCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _KPZTCollection;
        /// <summary>
        /// 开票状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> KPZTCollection
        {
            get { return _KPZTCollection; }
            set
            {
                _KPZTCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _DKZTCollection;
        /// <summary>
        /// 到款状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> DKZTCollection
        {
            get { return _DKZTCollection; }
            set
            {
                _DKZTCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _GDZTCollection;
        /// <summary>
        /// 归档状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> GDZTCollection
        {
            get { return _GDZTCollection; }
            set
            {
                _GDZTCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _BGYPCollection;
        /// <summary>
        /// 办公用品
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> BGYPCollection
        {
            get { return _BGYPCollection; }
            set
            {
                _BGYPCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _XMYQSPZTCollection;
        /// <summary>
        /// 项目延期审批状态
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> XMYQSPZTCollection
        {
            get { return _XMYQSPZTCollection; }
            set
            {
                _XMYQSPZTCollection = value;
            }
        }

        protected ObservableCollection<EIA.Basic.Model.DicItem> _TJXSCollection;
        /// <summary>
        /// 提奖系数
        /// </summary>
        public ObservableCollection<EIA.Basic.Model.DicItem> TJXSCollection
        {
            get { return _TJXSCollection; }
            set
            {
                _TJXSCollection = value;
            }
        }
    }

    public class DicTypes
    {
        public const string HYLX = "HYLX";//'行业类型'
        public const string XMLX = "XMLX";//'项目类型'
        public const string XMSZD = "XMSZD";//'项目所在地'
        public const string XMSPBM = "XMSPBM";//'项目审批部门'
        public const string XMLY = "XMLY";//'项目来源'
        public const string XMJD = "XMJD";//'项目进度'
        public const string DKFS = "DKFS";//'到款方式'
        public const string HTQDZT = "HTQDZT";//'合同签订主体'
        public const string HTZT = "HTZT";//'合同状态'
        public const string KPZT = "KPZT";//'开票状态'
        public const string DKZT = "DKZT";//'到款状态'
        public const string GDZT = "GDZT";//'归档状态'
        public const string BGYP = "BGYP";//'办公用品'
        public const string KCJS = "KCJS";//'扣除基数'
        public const string JSDW = "JSDW";//'建设单位'
        public const string XMYQSPZT = "XMYQSPZT";//'项目延期审批状态'
        public const string TJXS = "TJXS";//'提奖系数'
    }
}
